package common.statistics.jvm_info;

import java.util.HashMap;
import java.util.Map;


public class GarbageCollectorMXBeanNameToGarbageCollectorStatusMap
{
    public final Map<String, GarbageCollectorStatus> garbageCollectorMXBeanNameToGarbageCollectorStatusMap = new HashMap<String, GarbageCollectorStatus>();

    public String toString()
    {
        return "\tGC Names\t" + garbageCollectorMXBeanNameToGarbageCollectorStatusMap.keySet() + "\n";
    }

    public String getDeltaString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("\n\t [delta gc info] => \n");
        sb.append("\t\t ");
        sb.append(String.format("%-20s | %-18s | %-18s | %-18s | %-18s | %-18s | %-18s | %-18s | %-18s \n", "NAME", "$collectionCount", "totalCollectionCount", "maxCollectionCount", "minCollectionCount", "$collectionTime", "totalCollectionTime", "maxCollectionTime", "minCollectionTime"));
        for (GarbageCollectorStatus garbageCollectorStatus : garbageCollectorMXBeanNameToGarbageCollectorStatusMap.values())
        {
            sb.append("\t\t ");
            sb.append(String.format("%-20s | %-18s | %-18s | %-18s | %-18s | %-18s | %-18s | %-18s | %-18s \n",
                    garbageCollectorStatus.name, garbageCollectorStatus.$collectionCount, garbageCollectorStatus.totalCollectionCount, garbageCollectorStatus.maxCollectionCount, garbageCollectorStatus.minCollectionCount,
                    String.format("%,.3fs", (float) garbageCollectorStatus.$collectionTime / 1000),
                    String.format("%,.3fs", (float) garbageCollectorStatus.totalCollectionTime / 1000),
                    String.format("%,.3fs", (float) garbageCollectorStatus.maxCollectionTime / 1000),
                    String.format("%,.3fs", (float) garbageCollectorStatus.minCollectionTime / 1000)));

        }
        return sb.toString();
    }

    public String getTotalString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append("\n\t [total gc info] => \n");
        sb.append("\t\t ");
        sb.append(String.format("%-20s | %-18s | %-18s | %-18s | %-18s | %-18s | %-18s \n", "NAME", "totalCollectionCount", "maxCollectionCount", "minCollectionCount", "totalCollectionTime", "maxCollectionTime", "minCollectionTime"));
        for (GarbageCollectorStatus garbageCollectorStatus : garbageCollectorMXBeanNameToGarbageCollectorStatusMap.values())
        {
            sb.append("\t\t ");
            sb.append(String.format("%-20s | %-18s | %-18s | %-18s | %-18s | %-18s | %-18s \n",
                    garbageCollectorStatus.name, garbageCollectorStatus.totalCollectionCount, garbageCollectorStatus.maxCollectionCount, garbageCollectorStatus.minCollectionCount,
                    String.format("%,.3fs", (float) garbageCollectorStatus.totalCollectionTime / 1000),
                    String.format("%,.3fs", (float) garbageCollectorStatus.maxCollectionTime / 1000),
                    String.format("%,.3fs", (float) garbageCollectorStatus.minCollectionTime / 1000)));

        }
        return sb.toString();
    }
}
